package com.sikao.app.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sikao.app.R;
import com.sikao.app.bean.ProductIndexBean;
import com.sikao.app.utils.Utils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by y50 on 2016/5/23.
 */
public class ProductIndexAdapter extends BaseAdapter {

	private Context context;
	List<ProductIndexBean> productIndexBeanList;
	public ProductIndexAdapter(Context context,List<ProductIndexBean> productIndexBeanList){
		this.context = context;
		this.productIndexBeanList=productIndexBeanList;
	}
	@Override
	public int getCount() {
		return productIndexBeanList.size();
	}

	@Override
	public Object getItem(int position) {
		return productIndexBeanList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return Long.parseLong(productIndexBeanList.get(position).getId());
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		 if(convertView==null){
			 convertView = View.inflate(context, R.layout.product_index_list_item,null);
			 convertView.setTag(new ViewHolder(convertView));
		 }
		//if (position == 0 || position == 3)
		//((ProductIndexBean)getItem(position)).setName("大富科技的谁离开房间卡时间段付款了我也不知道这是什么情况啊就将计就计");
		initializeViews((ProductIndexBean)getItem(position), (ViewHolder) convertView.getTag());

		return convertView;
	}

	private void initializeViews(ProductIndexBean productIndexBean, ViewHolder viewHolder) {
		viewHolder.keytv.setText(productIndexBean.getName());
		viewHolder.valuetv.setText(productIndexBean.getDefault_value_toString());
		Utils.showLog("====招标的产品指标"+productIndexBean.getDefault_value_toString());

	}

	public class ViewHolder {
		public final TextView keytv;
		public final TextView valuetv;
		public final View root;

		public ViewHolder(View root) {
			keytv = (TextView) root.findViewById(R.id.key_tv);
			valuetv = (TextView) root.findViewById(R.id.value_tv);
			this.root = root;
		}
	}
}
